package com.qf.question.controller;

import com.qf.common.entity.Result;
import com.qf.common.entity.StatusCode;
import com.qf.question.entity.Question;
import com.qf.question.entity.QuestionCategory;
import com.qf.question.service.QuestionCategoryService;
import com.qf.question.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述：
 *
 * @author ash-lei
 * @date 2021/10/14 11:08
 */
@Controller
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    @GetMapping("/findById/{id}")
    @ResponseBody
    public Result findById(@PathVariable Integer id) {
        Question question = questionService.findById(id);
        //return question;

        return new Result(true, StatusCode.ERROR, "查询成功",question);
        //return 111;
    }

    @ResponseBody
    @GetMapping("/findByType")
    public List<Question> findByType(String type) {
        Question q = new Question();
        Integer i = Integer.parseInt(type);
        q.setKid(i);
        List<Question> byType = questionService.findByType(q);

        //for (Question question : byType) {
        //    System.out.println(question);
        //}
        //System.out.println("sss");
        return byType;
    }

    @Autowired
    private QuestionCategoryService questionCategoryService;

    //@ResponseBody
    @GetMapping("/findAllTypes")
    public String findAllTypes(Model model) {
        List<QuestionCategory> allType = questionCategoryService.findAllType();
        model.addAttribute("allType",allType);
        return "question";

    }





    @GetMapping("/test")
    public String test(Model model) {
        //model.addAttribute()
        model.addAttribute("thText","thText" );
        return "question";

    }

}
